package com.jiangjiang.eshop.order.status;

import com.jiangjiang.eshop.common.help.DateHelper;
import com.jiangjiang.eshop.order.constant.OrderStatus;
import com.jiangjiang.eshop.order.dto.OrderInfoDTO;
import com.jiangjiang.eshop.order.service.OrderInfoService;

import java.util.Date;

/**
 * @Author Jianghaowen
 * @Date 2021/8/24
 * @Description: TODO
 * @Version V1.0
 **/
public  abstract class AbstractOrderState implements OrderState {

    /**
     * 日期辅助组件
     */
    protected DateHelper dateHelper;
    /**
     * 订单管理Service组件
     */
    protected OrderInfoService orderInfoService;


    public AbstractOrderState(DateHelper dateHelper, OrderInfoService orderInfoService) {
        this.dateHelper = dateHelper;
        this.orderInfoService = orderInfoService;
    }

    @Override
    public void doTransition(OrderInfoDTO order) throws Exception {
        Integer state = getOrderState();
        order.setOrderStatus(state);
        orderInfoService.updateState(order.getId(), state);
    }

    /**
     * 获取当前流转的的状态
     * @return
     * @throws Exception
     */
    protected abstract Integer getOrderState() throws  Exception;

    @Override
    public Boolean canCancel(OrderInfoDTO order) throws Exception {
        return false;
    }

    @Override
    public Boolean canPay(OrderInfoDTO order) throws Exception {
        return false;
    }

    @Override
    public Boolean canConfirmReceipt(OrderInfoDTO order) throws Exception {
        return false;
    }

    @Override
    public Boolean canApplyReturnGoods(OrderInfoDTO order) throws Exception {
        return false;
    }
}
